# 获取百度一下按钮
import urllib.request
import urllib.parse
from http.client import HTTPResponse
import lxml.etree

url = "https://www.baidu.com/"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
}

request = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(request)  # type:HTTPResponse
content = response.read().decode("utf8")
# xpath的使用步骤 1）将字符串转etree对象，2）使用xpath查找信息
etree_html = lxml.etree.HTML(content)  # type:lxml.etree._Element # 返回的是页面的html元素节点
values = etree_html.xpath("//input[@id='su']/@value")

print(values[0])
